package com.umgsai.wx.backend.test;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.google.common.collect.Lists;
import com.umgsai.wx.backend.BaseTest;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

import java.math.BigDecimal;
import java.util.List;

@Slf4j
public class FixPartRefundOrder extends BaseTest {


	@Data
	public static class HotelOrderData {

		@ExcelProperty(value = "appointId", index = 1)
		private String appointId;

		@ExcelProperty(value = "hotelOrderId", index = 2)
		private String hotelOrderId;

		@ExcelProperty(value = "supplierOrderId", index = 3)
		private String supplierOrderId;

		@ExcelProperty(value = "appointAmount", index = 5)
		private BigDecimal appointAmount;

		@ExcelProperty(value = "realGetAmount", index = 7)
		private BigDecimal realGetAmount;

		@ExcelProperty(value = "invoiceAmount", index = 9)
		private BigDecimal invoiceAmount;

		@ExcelProperty(value = "totalInvoiceAmount", index = 10)
		private BigDecimal totalInvoiceAmount;
	}

	@Data
	public static class ExcelDataListener extends AnalysisEventListener<HotelOrderData> {

		private List<HotelOrderData> excelDataList = Lists.newArrayList();

		@Override
		public void invoke(HotelOrderData data, AnalysisContext context) {

			excelDataList.add(data);
		}

		@Override
		public void doAfterAllAnalysed(AnalysisContext context) {
			//读取结束会调用该方法
			System.out.println("end...");
		}
	}

	@Test
	public void test() throws Exception {
		String excelPath = "D:\\9.13_partRefund.xlsx";
		ExcelDataListener excelDataListener = new ExcelDataListener();
		EasyExcel.read(excelPath, HotelOrderData.class, excelDataListener).sheet().doRead();
		List<HotelOrderData> excelDataList = excelDataListener.getExcelDataList();
		for (HotelOrderData hotelOrderData : excelDataList) {
//			System.out.printf("update oa_onlineappoint set appointAmount=%s, invoiceAmount=%s, realGetAmount=%s where hotelOrderId=%s;\n",
//					hotelOrderData.getAppointAmount(), hotelOrderData.getInvoiceAmount(), hotelOrderData.getRealGetAmount(), hotelOrderData.getHotelOrderId());
			System.out.printf("update ord_info set InvoiceAmount = %s where OrderId = %s;\n", hotelOrderData.getTotalInvoiceAmount(), hotelOrderData.getSupplierOrderId());
		}
	}
}
